from flask import current_app, jsonify
from flask import render_template
from flask import send_file

from info import constants
from info.response_code import RET, error_map
from info.models import House,Area
from info.modules.index import index_blu
from flask import redirect, render_template


@index_blu.route("/api/v1.0/areas")
def areas():
    areas_li = []
    try:
        areas = Area.query.filter().all()
    except Exception as e:
        current_app.logger.error(e)

    areas_li = [area.to_dict() for area in areas]

    return jsonify(data=areas_li, error="成功",errno=RET.OK)


@index_blu.route('/api/v1.0/houses/index')
def index1():

    houses_li = []
    try:
        houses = House.query.filter().limit(constants.HOME_PAGE_MAX_HOUSES)
    except Exception as e:
        current_app.logger.error(e)

    houses_li=[house.to_basic_dict() for house in houses]

    return jsonify(data=houses_li, error="成功", errno=RET.OK)
